#include <iostream>
#include <algorithm>
#include <vector>

class Person
{
private:
    int age;
    std::string name;

public:
    Person(int age, std::string name) : name(name), age(age) {}
    int getAge() const
    {
        return age;
    }

    std::string getName() const
    {
        return name;
    }
};

std::ostream &operator<<(std::ostream &os, const Person &p)
{
    os << "{" << p.getName() << ", " << p.getAge() << "} ";
    return os;
}

struct Print
{
    void operator()(const Person &p)
    {
        std::cout << p;
    }
};

struct PersonEqualPredicate
{
    bool operator()(const Person &p1, const Person &p2)
    {
        return p1.getAge() == p2.getAge() && p1.getName() == p2.getName();
    }
};

int main(int argc, char const *argv[])
{
    std::vector<Person> personVector{};
    for (int i = 0; i < 10; i++)
    {
        personVector.push_back(Person(i + 18, std::string("Person") + std::to_string(i)));
    }

    personVector.insert(personVector.begin() + 5, Person(23, "Person5"));

    std::for_each(personVector.begin(), personVector.end(), Print());
    std::cout << std::endl;

    std::vector<Person>::const_iterator it = std::adjacent_find(personVector.begin(), personVector.end(), PersonEqualPredicate());
    if (it != personVector.end())
    {
        std::cout << *it << std::endl;
    }
    else
    {
        std::cout << "没有找到相同的" << std::endl;
    }

    return EXIT_SUCCESS;
}
